class Person {
  name = "admin";
  age: number = 10;
  say(n: number): void {
    console.log("hello world", n);
    console.log(this.name, this.age);
  }
  constructor(name: string, age: number) {
    this.name = name;
    this.age = age;
  }
}

let p = new Person("李四", 22);
// p.name = "张三";
// p.age = 20;
console.log(p);
p.say(88);

// 类的继承
class Animal {
  readonly PI: number = 3.14;
  private name: string;
  age: number;
  constructor(name: string, age: number) {
    this.name = name;
    this.age = age;
  }
  peiWan() {
    console.log("陪你玩", this.name);
  }
}

class Dog extends Animal {
  quanFei() {
    console.log("犬吠");
  }
  eatBone() {
    console.log("吃骨头");
  }
}
class Cat extends Animal {
  zhuaLaoShu() {
    console.log("抓老鼠", this.age);
  }
}

let cat = new Cat("小猫", 2);
console.log(cat);
console.log(cat.PI);

cat.peiWan();
cat.zhuaLaoShu();

// let dog = new Dog("大黄", 3);
// console.log(dog);
// dog.peiWan();
// dog.quanFei();
// dog.eatBone();

interface Singable {
  name: string;
  sing(): void;
}
interface Jumpable {
  height: number;
  jump(): void;
}

class Person2 implements Singable, Jumpable {
  name: string;
  sing(): void {
    console.log("唱");
  }
  constructor(name: string, height: number) {
    this.name = name;
    this.height = height;
  }
  height: number;
  jump(): void {
    console.log("跳", this.height);
  }
}

let p2 = new Person2("李四", 1.7);
console.log(p2);
p2.sing();

p2.jump();
